//
//  UIImageViewAddtion.m
//  DzNews
//
//  Created by zengyuan on 13/12/13.
//  Copyright (c) 2013 zengyuan. All rights reserved.
//

#import "UIImageViewAddtion.h"
#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"

@implementation UIImageView(Alpha)
-(void)setImageWithAnimation:(NSString *)url placeholder:(NSString *)placeholder{
    
    __unsafe_unretained typeof(self) weakSelf = self;

    [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:
                                                                      placeholder]
                completed:
     ^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
         

         if (image) {
             if (cacheType == SDImageCacheTypeNone) {
                 weakSelf.image=image;
                 weakSelf.alpha=0;
                 
                 [UIView animateWithDuration:0.5 animations:^{
                     weakSelf.alpha=1;
                 }];
             }else{
                 weakSelf.image=image;
             }
         }else{
             weakSelf.image=[UIImage imageNamed: placeholder];
             if (error) {
//                 DLog(@"error=%@", error);
             }
         }
         

         
     }];
    
}

@end
